<template>
  <div class="login">
    <div class="welcome">用户注册</div>
    <div class="login-form">
      <div class="login-inp"><label>账号</label>
        <input style="display: none;" />
        <input type="text" placeholder="账号" v-model.trim="username"></div>
      <div class="login-inp"><label>密码</label>
        <input type="password" placeholder="密码" v-model.trim="passwords"></div>
      <div class="login-inp"><label>确认</label>
        <input type="password" placeholder="密码" v-model.trim="comfirmPwd"></div>
      <div class="login-inp"><a href="javascript:void(0)" @click="register">立即注册</a></div>
    </div>
    <div class="login-txt"><a href="javascript:void(0)" @click="$router.push('/login')">已有账号，立即登录</a></div>
  </div>
</template>

<script>
import { Toast } from 'mint-ui';
import { Indicator } from 'mint-ui';
import common from '../../common/common';
export default {
  name: 'Register',
  data () {
    return {
      username: '',
      passwords: '',
      comfirmPwd:'',
      isSave:[],
      options: [
        {
          label: '记住密码',
          value: '1'
        }
      ]
    };
  },
  methods: {
    register () {
      if(!this.username) return Toast({message: '请输入用户名！', position: 'bottom'});
      if(!this.passwords) return Toast({message: '请输入密码！', position: 'bottom'});
      if(!this.comfirmPwd) return Toast({message: '请输确认密码！', position: 'bottom'});
      if(this.passwords !== this.comfirmPwd) return Toast({message: '两次密码不一致！', position: 'bottom'});

      const params = {
        username:this.username,
        password: this.passwords
      };

      Indicator.open();
      common.request('register', params).then(res=>{
        var $data = res.data;
        if ($data.code > 0) {
          Toast($data.msg);
          setTimeout(()=>{
            this.$router.push('/logout');
          }, 1e3);
          Indicator.close();
        } else {
          Toast({message: $data.msg, position: 'bottom'});
          Indicator.close();
        }
        // console.log(res);
      });
    }
  }
};
</script>

<style scoped>
@import url('../login/login-theme.css');
.footer-reg{
  padding: 20px 0 20px;
  width: 100%;
  font-size: .875rem;
  text-align: center;
}
.footer-reg a {
  color: #5184BC;
}
</style>
